﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using MVP;
using System.Globalization;

namespace WinForms
{
    public partial class LaporanSemester : UserControl, ILaporanSemesterView
    {
        LaporanSemesterPresenter _presenter;
        public LaporanSemesterPresenter GetPresenter()
        {
            return _presenter;
        }
        public LaporanSemester()
        {
            _presenter = new LaporanSemesterPresenter(this);
            InitializeComponent();
        }

        public LaporanSemester(String semester, String tahun)
            : this()
        {
            Semester = semester;
            Tahun = tahun;
        }

        #region ILaporanSemesterView Members

        public DataSet LppbopDataSet
        {
            set
            {
                BindingSource bindingSource = new BindingSource(this.components);
                bindingSource.DataSource = value;
                bindingSource.DataMember = "LaporanSemester";
                lapSemesterDataGridView.DataSource = bindingSource;
                lapSemesterBindingNavigator.BindingSource = bindingSource;
            }
            get 
            { 
                return (DataSet)((BindingSource)lapSemesterDataGridView.DataSource).DataSource; 
            }
        }

        public string Tahun
        { get; set; }

        public string Semester
        { get; set; }

        public void SendMessageInfo(string strMessage)
        {
            MessageBox.Show(strMessage, "Information Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public event EventHandler Save;

        public event EventHandler Initialize;

        #endregion

        private void updateToolStripButton_Click(object sender, EventArgs e)
        {
            ((BindingSource)lapSemesterDataGridView.DataSource).EndEdit();
            Save(sender, e);
            updateToolStripButton.Enabled = false;
        }

        private void LaporanSemester_Load(object sender, EventArgs e)
        {
            Initialize(sender, e);
            updateToolStripButton.Enabled = false;
            periodeToolStripLabel.Text = String.Format("LAPORAN SEMESTER {0} {1}", Semester, Tahun);
            lapSemesterDataGridView.AllowUserToAddRows = false;

            lapSemesterDataGridView.Columns["Id"].Visible = false;
            lapSemesterDataGridView.Columns["Semester"].Visible = false;
            lapSemesterDataGridView.Columns["Tahun"].Visible = false;

            lapSemesterDataGridView.Columns[3].HeaderText = "No.";
            lapSemesterDataGridView.Columns[3].Width = 30;

            lapSemesterDataGridView.Columns[4].HeaderText = "Uraian";
            lapSemesterDataGridView.Columns[4].Width = 300;

            lapSemesterDataGridView.Columns[5].HeaderText = "Prosentase Anggaran";
            lapSemesterDataGridView.Columns[5].ReadOnly = true;
            lapSemesterDataGridView.Columns[5].Width = 70;
            lapSemesterDataGridView.Columns[5].DefaultCellStyle.Format = "p";

            lapSemesterDataGridView.Columns[6].HeaderText = "Jumlah Anggaran";
            lapSemesterDataGridView.Columns[7].HeaderText = "Realisasi Triwulan I";
            lapSemesterDataGridView.Columns[8].HeaderText = "Realisasi Triwulan II";
            lapSemesterDataGridView.Columns[9].HeaderText = "Realisasi Triwulan III";
            lapSemesterDataGridView.Columns[10].HeaderText = "Realisasi Triwulan IV";
            lapSemesterDataGridView.Columns[11].HeaderText = "Jumlah Realisasi";
            lapSemesterDataGridView.Columns[12].HeaderText = "Prosentase Pajak";
            lapSemesterDataGridView.Columns[13].HeaderText = "Pajak Yang Diterima";
            lapSemesterDataGridView.Columns[14].HeaderText = "Pajak Yang Disetorkan";
            lapSemesterDataGridView.Columns[15].HeaderText = "Sisa Dana";
            lapSemesterDataGridView.Columns[16].HeaderText = "Keterangan";

            for (int i = 6; i < 16; i++)
            {
                lapSemesterDataGridView.Columns[i].ReadOnly = true;
                lapSemesterDataGridView.Columns[i].Width = 100;
                lapSemesterDataGridView.Columns[i].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
                lapSemesterDataGridView.Columns[i].DefaultCellStyle.Format = "c";
            }

            lapSemesterDataGridView.Columns[12].Width = 70;
            lapSemesterDataGridView.Columns[12].DefaultCellStyle.Format = "p";
        }

        private void lapSemesterDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            updateToolStripButton.Enabled = true;
        }
    }
}
